package flc.ast.utils;

import android.annotation.SuppressLint;
import android.content.Context;
import android.telephony.CellInfo;
import android.telephony.CellInfoLte;
import android.telephony.CellSignalStrengthLte;
import android.telephony.TelephonyManager;

public class SignalStrengthMonitor {
    private TelephonyManager mTelephonyManager;

    public SignalStrengthMonitor(Context context) {
        mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    }

    @SuppressLint("MissingPermission")
    public int getSignalStrength() {
        int signalStrength = -1;
        for (CellInfo cellInfo : mTelephonyManager.getAllCellInfo()) {
            if (cellInfo instanceof CellInfoLte) {
                CellSignalStrengthLte signalStrengthLte = ((CellInfoLte) cellInfo).getCellSignalStrength();
                signalStrength = signalStrengthLte.getDbm();
                break;
            }
        }
        return signalStrength;
    }
}